namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_eorderLog 的摘要说明
/// </summary>
public class t_eorderLog:IEntityUtil
{
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private EorderLog __eorderLog;
	public String id  
	{
		get{return __eorderLog.id;}
		set{ __eorderLog.id=value;}
	}
	public String orderID  
	{
		get{return __eorderLog.orderID;}
		set{ __eorderLog.orderID=value;}
	}
	public DateTime orderTime  
	{
		get{return __eorderLog.orderTime;}
		set{ __eorderLog.orderTime=value;}
	}
	public int orderState  
	{
		get{return __eorderLog.orderState;}
		set{ __eorderLog.orderState=value;}
	}
	private static  EorderLogDao dao=(EorderLogDao)SpringContext.Context.GetObject("EorderLogDao");
	public static EorderLogDao DAO
	{
		get{return dao;}
		
	}
	
	public t_eorderLog()
	{
		__eorderLog=new EorderLog();
	  	id="";
	  	orderID="";
	  	orderTime=DateTime.Now;
	  	orderState=consts.int_min;
	  // dao=(EorderLogDao)SpringContext.Context.GetObject("EorderLogDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"主键");
		colNames.Add("id");
		m_colLabels.Add("orderID", @"主键");
		colNames.Add("orderID");
		m_colLabels.Add("orderTime", @"时间");
		colNames.Add("orderTime");
		m_colLabels.Add("orderState", @"状态");
		colNames.Add("orderState");
	  }
	
	}
	public t_eorderLog(EorderLog entity )
	{
		__eorderLog=entity;
		
	  // dao=(EorderLogDao)SpringContext.Context.GetObject("EorderLogDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"主键");
		colNames.Add("id");
		m_colLabels.Add("orderID", @"主键");
		colNames.Add("orderID");
		m_colLabels.Add("orderTime", @"时间");
		colNames.Add("orderTime");
		m_colLabels.Add("orderState", @"状态");
		colNames.Add("orderState");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(EorderLog));}
     }
	public const string ENTITYNAME="t_eorderLog";
	public const int SEQN0=288;
	
    public void checkAdd()
    {
		int len;
	
	len=id.Trim().Length;
	if(len>32)
		 throw (new Exception("主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("主键不能为空!"));	
	
 if(id=="0")
	 throw (new Exception("主键是主健，框架要求值不能为0"));				

	
	len=orderID.Trim().Length;
	if(len>32)
		 throw (new Exception("主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("主键不能为空!"));	
	

	//try{Convert.ToDateTime(orderTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	orderTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入时间"));

	//try{Convert.ToInt32(orderState);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	orderState<consts.int_min+1)
			throw (new Exception("请输入状态"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("orderID", orderID);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==0)
			return;
		EorderLog obj=list[0] as EorderLog;
//唯一性异常消息抛出
		if( obj.orderID==orderID)
		{
			throw (new Exception(string.Format("主键:{0}已经存在",orderID)));	
		}
	//end unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	
	len=id.Trim().Length;
	if(len>32)
		 throw (new Exception("主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("主键不能为空!"));	
	
 if(id=="0")
	 throw (new Exception("主键是主健，框架要求值不能为0"));				

	
	len=orderID.Trim().Length;
	if(len>32)
		 throw (new Exception("主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("主键不能为空!"));	
	

	//try{Convert.ToDateTime(orderTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	orderTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入时间"));

	//try{Convert.ToInt32(orderState);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	orderState<consts.int_min+1)
			throw (new Exception("请输入状态"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("id", id);
		crit=Restrictions.Or(crit,Restrictions.Eq("orderID", orderID));
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__eorderLog);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByid()
    {
    
        try
        {
          dao.Delete(__eorderLog);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__eorderLog);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,id);	
m_updateRow(rowNo,ii++,orderID);	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,80,"主键");
			m_insertHead(ii++,80,"主键");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,id);
     	m_insertRow(0,ii++,orderID);
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,80,"主键");
			m_insertHead(ii++,80,"主键");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(EorderLog obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,obj.id.ToString());
m_insertRow(j,ii++,obj.orderID.ToString());
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		EorderLog obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__eorderLog=obj;
            	return true;
            }
        
    }
    public static t_eorderLog Get(DetachedCriteria dc)
    {
    	
    	EorderLog obj=((EorderLogDao)SpringContext.Context.GetObject("EorderLogDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_eorderLog( obj );
        
    }
	 public static t_eorderLog GetById(String val)
	 {
	 	EorderLog obj=((EorderLogDao)SpringContext.Context.GetObject("EorderLogDao"))
	 	.GetById(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_eorderLog( obj );
	 	
	 	
	 }
	 public  bool InitById(String val)
	 {
	 	

	 	EorderLog obj=dao.GetById(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__eorderLog=obj;
	 		return true;
	 	}
	 	
	 	
	 }
	 public static t_eorderLog GetByOrderID(String val)
	 {
	 	EorderLog obj=((EorderLogDao)SpringContext.Context.GetObject("EorderLogDao"))
	 	.GetByOrderID(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_eorderLog( obj );
	 	
	 	
	 }
	 public  bool InitByOrderID(String val)
	 {
	 	

	 	EorderLog obj=dao.GetByOrderID(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__eorderLog=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			Controls["id"].Text=id;
		}
		if(Controls["orderID"]!=null)
		{
			Controls["orderID"].Text=orderID;
		}
		if(Controls["orderTime"]!=null)
		{
			Controls["orderTime"].Text=			orderTime.ToString().CompareTo("1001-1-1")<0?"":string.Format("{0:g}",orderTime);
		}
		if(Controls["orderState"]!=null)
		{
			Controls["orderState"].Text=(				  string.Format("{0}",orderState)				  )
;
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_eorderLog Init(EorderLog item)
    {
        __eorderLog=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			
			if(Controls["id"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["id"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{id=v;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
			else
			{
				try{id=Controls["id"].Text;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["orderID"]!=null)
		{
			
			if(Controls["orderID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["orderID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{orderID=v;}
				catch
				{
					 Controls["orderID"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
			else
			{
				try{orderID=Controls["orderID"].Text;}
				catch
				{
					 Controls["orderID"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["orderTime"]!=null)
		{
			
			if(Controls["orderTime"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["orderTime"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{orderTime=(v==""?new DateTime(1000,1,1):Convert.ToDateTime(v));}
				catch
				{
					 Controls["orderTime"].Focus();
					throw  (new Exception("时间格式不正确！！"));
				}
				
			}
			else
			{
				try{orderTime=(Controls["orderTime"].Text==""?new DateTime(1000,1,1):Convert.ToDateTime(Controls["orderTime"].Text));}
				catch
				{
					 Controls["orderTime"].Focus();
					throw  (new Exception("时间格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["orderState"]!=null)
		{
			
			if(Controls["orderState"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["orderState"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{orderState=(v==""?consts.int_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["orderState"].Focus();
					throw  (new Exception("状态格式不正确！！"));
				}
				
			}
			else
			{
				try{orderState=(Controls["orderState"].Text==""?consts.int_min:Convert.ToInt32(Controls["orderState"].Text));}
				catch
				{
					 Controls["orderState"].Focus();
					throw  (new Exception("状态格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
